package com.walk.zworld.ui.fragment

import android.content.Intent
import android.view.View
import com.walk.zworld.mvvm.Constant
import com.walk.zworld.mvvm.vm.KnowledgeViewModel
import com.walk.zworld.ui.activity.KnowledgeActivity
import com.walk.zworld.ui.adapter.SysKnowledgeAdapter
import com.base.lib.base.view.BaseMvvmListFragment
import com.base.lib.httpUtils.KnowledgeTreeBody
import java.io.Serializable

class SysKnowledgeFragment : BaseMvvmListFragment<KnowledgeTreeBody, KnowledgeViewModel, SysKnowledgeAdapter>() {

    companion object {
        fun newInstance() = SysKnowledgeFragment()
    }
    override fun onBindAdapter(): Class<SysKnowledgeAdapter> = SysKnowledgeAdapter::class.java

    override fun onBindViewModel(): Class<KnowledgeViewModel>  = KnowledgeViewModel::class.java

    override fun initView(view: View) {
        enableLoadMore(false)
        mAdapter.run {
            setOnItemClickListener1(object : SysKnowledgeAdapter.OnItemClickListener1 {
                override fun onClick(bean: KnowledgeTreeBody, pos: Int) {
                    Intent(activity, KnowledgeActivity::class.java).run {
                        putExtra(Constant.CONTENT_TITLE_KEY, bean.name)
                        putExtra(Constant.CONTENT_DATA_KEY, bean as Serializable)
                        putExtra("postion", pos)
                        startActivity(this)
                    }
                }
            })
        }
    }

    override fun initData() {
        onRefreshEvent()
    }

}